<?php

	class AlbumModel {
		private $imgs;
		private $id;
		private $name;
		private $nbImgs;
		
		function __construct ($albumId, $albumName, $nbImgs, array $imgs = array()) {
			$this->id = $albumId;
			$this->name = $albumName;
			$this->nbImgs = $nbImgs;
			$this->imgs = $imgs;
		}
		
		function getId() {
			return $this->id;
		}
		function getName() {
			return $this->name;
		}
		function getImgs() {
			return $this->imgs;
		}
		function getNbImages() {
			return $this->nbImgs;
		}
		function getImage($i) {
			if ($i < 0)
				$i = 1;
			elseif ($i > $this->getNbImages())
				$i = count($this->imgs)-1;
			return $this->imgs[$i];
		}
		function getCover() {
			if ($this->getNbImages() > 0) {
				$i = rand(0, count($this->imgs)-1);
				$ret = $this->imgs[$i];
			} else {
				$ret = new Image(DAO::urlPath.'default.gif', null, null, null, 'default.gif', 0, 0);
			}
			return $ret;
		}
		
		function setName($name) {
			$this->name = $name;
		}
		function setImgs(array $imgs) {
			$this->imgs = $img;
		} 
		function addImg(Image $img) {
			$this->imgs[] = $img;
			$this->nbImgs++;
		}
	}